package com.lz.ht.service.serviceImpl;

import com.lz.ht.dao.RoomDao;
import com.lz.ht.model.Book;
import com.lz.ht.model.DropInformation;
import com.lz.ht.model.Room;
import com.lz.ht.model.Roombook;
import com.lz.ht.page.PageModel;
import com.lz.ht.service.RoomService;
import com.lz.ht.util.ToolKit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName: RoomServiceImpl
 * @Description:
 * @Author: CHonghao
 * @Date: 2021/7/9 11:27
 * @Version: V1.0
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomDao roomDao;

    @Override
    public List<Room> findPageList(PageModel<Room> page, Room room) throws Exception {
        HashMap<String, Object> hashMap = ToolKit.javaBeanToMap(room);
        hashMap.put("msFirst", page.getMsFirst());
        hashMap.put("msLast", page.getMsLast());
        return roomDao.findListByMapLimit(hashMap);
    }

    @Override
    public long findCount(Room room) throws Exception {
        HashMap<String, Object> hashMap = ToolKit.javaBeanToMap(room);
        return roomDao.findCountByMap(hashMap);
    }

    @Override
    public void add(Room room) {
        roomDao.add(room);
    }

    @Override
    public Room findById(String rno) {
        return roomDao.selectByPrimaryKey(rno);
    }

    @Override
    public void updateById(Room room) {
        roomDao.updateByPrimaryKeySelective(room);
    }

    @Override
    public void deleteById(String rno) {
        roomDao.deleteByPrimaryKey(rno);
    }

    @Override
    public List<Roombook> findFreeRoomList(PageModel<Roombook> page, Roombook roombook) throws Exception {
        HashMap<String, Object> hashMap = ToolKit.javaBeanToMap(roombook);
        hashMap.put("msFirst", page.getMsFirst());
        hashMap.put("msLast", page.getMsLast());
        return roomDao.findFreeRoomList(hashMap);
    }

    @Override
    public long findFreeRoomCount(Roombook roombook) throws Exception {
        HashMap<String, Object> hashMap = ToolKit.javaBeanToMap(roombook);
        return roomDao.findFreeCountByMap(hashMap);
    }

    @Override
    public DropInformation dropRoom(DropInformation dropInformation) {
        return roomDao.dropRoom(dropInformation);
    }

    @Override
    public void addbook(Book book) {
        roomDao.addbook(book);
    }
}
